import { RequestConfig } from 'umi';

// 运行时配置
// 请求返回统一配置
export const request: RequestConfig = {
  credentials: 'include',
  timeout: 10000,
  errorConfig: {
    errorPage: '@/404.tsx',
    // convert result
    adaptor: resData => {
      return {
        ...resData,
        showType: resData.code,
        success: resData.ok,
        errorMessage: resData.message,
      };
    },
  },
  // request AOP
  middlewares: [
    // async function middlewareA(ctx, next) {
    //   // console.log('A before');
    //   await next();
    //   // console.log('A after');
    // }
  ],
  responseInterceptors: [
    
  ]
};

// 注册 dva
export const dva = {
  config: {
    onError(err: any) {
      err.preventDefault();
      console.error(err.message);
    },
  },
};
